package com.baosight.xcyber.tm.re.domain;

import com.alibaba.fastjson.JSONObject;
import com.zeroc.IceGrid.NodeDescriptor;
import com.zeroc.IceGrid.ServerDescriptor;
import com.zeroc.IceGrid.ServerInstanceDescriptor;
import com.zeroc.IceGrid.TemplateDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class UINode extends UITreeNode {
    public static Logger logger= LoggerFactory.getLogger(UINode.class);
    NodeDescriptor nodeDescriptor;
    public UINode(String nodeName,
                  NodeDescriptor nodeDescriptor,
                  Map<String, TemplateDescriptor> serverTemplates,
                  Map<String,TemplateDescriptor> serviceTemplates){
        this.type="NODE";
        this.serverTemplates=serverTemplates;
        this.serviceTemplates=serviceTemplates;
        this.name=nodeName;
        this.nodeDescriptor=nodeDescriptor;
        param= (JSONObject) JSONObject.toJSON(nodeDescriptor);
        List<ServerInstanceDescriptor> serverInstances = nodeDescriptor.serverInstances;
        List<ServerDescriptor> servers = nodeDescriptor.servers;
        List<UIServer> collect1 = serverInstances.stream().map(
                item->new UIServer(item,serverTemplates,serviceTemplates)).collect(Collectors.toList());
        List<UIServer> collect2 = servers.stream().map(
                item->new UIServer(item,serverTemplates,serviceTemplates)
        ).collect(Collectors.toList());
        getChildren().addAll(collect1);
        getChildren().addAll(collect2);
    }
}
